<?php

class OPFaction {
	/**
	* -------------------------------------------------------------------------
	*
	* 									Const
	*
	* -------------------------------------------------------------------------
	*/

	/**
	* Rebels faction name
	*/
	const REBELS_FACTION = 'Rebels';
	
	/**
	 * Oppressors faction name
	 */
	const OPPRESSORS_FACTION = 'Oppressors';
	
	/**
	* -------------------------------------------------------------------------
	*
	* 									Attributes
	*
	* -------------------------------------------------------------------------
	*/
	
	/**
	 * Power bar of the faction
	 * 
	 * @var OPPowerBar
	 */
	protected $powerBar;
	
	/**
	* Faction members
	*
	* @var array<OPPlayer>
	*/
	protected $factionMembers;
	
	/**
	 * -------------------------------------------------------------------------
	 * 
	 * 									Static
	 * 
	 * -------------------------------------------------------------------------
	 */
	
	/**
	* Static constructor creating a new Faction with a power bar
	*
	* @param $powerBar
	* @return OPFaction
	*/
	public static function newWithPowerBar($powerBar){
		$newFaction = new OPFaction();
		$newFaction->setPowerBar($powerBar);
	
		return $newFaction;
	
	}
	
	/**
	* -------------------------------------------------------------------------
	*
	* 									Dynamic
	*
	* -------------------------------------------------------------------------
	*/
	
	/**
	* -------------------------------------------------------------------------
	* 									Setters
	* -------------------------------------------------------------------------
	*/
	
	/**
	 * Set the power bar to the faction
	 * 
	 * @param $powerBar
	 * @return OPFaction
	 */
	public function setPowerBar($powerBar){
		$this->powerBar = $powerBar;
		
	}
	
	/**
	 * Add a member to the faction members
	 * 
	 * @param $aPlayer
	 * @return OPFaction
	 */
	public function addMember($aPlayer) {
		$this->factionMembers[] = $aPlayer;
		
		return $this;
		
	}
	
	/**
	* Remove a member from the faction members
	*
	* @param $aPlayer
	* @return OPFaction
	*/
	public function removeMember($aPlayer) {
		foreach ($this->factionMembers as $key => $factionMember) {
			if ($aPlayer->emei() == $factionMember->emei()) {
				unset($this->factionMembers[$key]);
				
			}
			
		}
	
		return $this;
		
	}

	/**
	* -------------------------------------------------------------------------
	* 									Getters
	* -------------------------------------------------------------------------
	*/
	
	/**
	* Return the name of the faction
	*
	* @return string
	*/
	public function name() {
		throw new Exception('Subclass Responsability');
	
	}
	
	/**
	 * Return the power bar of the faction
	 * 
	 * @return OPPowerBar
	 */
	public function powerBar() {
		return $this->powerBar;
		
	}
	
	/**
	 * Return an array with faction members
	 * 
	 * @return array
	 */
	public function factionMembers() {
		return $this->factionMembers;
		
	}
	
	
}